<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<body  class="list">
<div th:replace="include/head.html::html"></div>

<div class="layui-form layui-card-header layuiadmin-card-header-auto">
    <div class="layui-form-item">
        <div class="layui-block">

            <div class="layui-inline">
                <label class="layui-form-label">用户</label>
                <div class="layui-input-block">
                    <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input"
                           style="margin-right: 30px;">
                </div>
            </div>

            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>

        </div>

    </div>
</div>

<form class="layui-fluid  layui-anim-upbit layui-anim layui-form">
    <div class="layui-card">
        <input type="hidden" id="oid" th:value="${userOid}">
        <!--表格中的数据 并不显示-->
        <div class="layui-card-body">
            <!--数据表格 -->
            <table class="layui-hidden" id="table" lay-filter="table"></table>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="submit" id="submit" value="确认">
    </div>
    <div class="layui-form-item layui-hide">
        <input type="text" name="oid" id="userOid" lay-verify="oid">
        <input type="text" name="name" id="userName" >
    </div>
</form>
<script type="text/javascript" th:inline="none">
    var table;
    layui.use(['jquery','table', 'layer','form'], function () {

        var $ = layui.$;
        table = layui.table; //很重要
        var form = layui.form;
        var laydate = layui.laydate;
        table.render({
            id: 'table'
            ,elem: '#table'
            , loading: true
            , method: 'post'
            ,url:'sysuser/getPage'
            ,cols: [[
                {type: 'radio'}
                , {field: 'oid' ,hide:true}
                , {field: 'account', title: '登录账号'}
                , {field: 'name', title: '用户名'}
                , {field: 'userType', title: '角色'}
            ]]
            ,page: true
            ,done:function (res, curr, countName) {
                $("table td").each(function (index,obj) {
                    if($(obj).attr("data-field") === "oid"){
                        if($(obj).find("div").text() === $("#oid").val()){
                            $(obj).prev().find(".layui-form-radio").click();
                        }
                    }
                })
            }
        });

        //监听搜索
        form.on('submit(search)', function (data) {
            var field = data.field;
            console.log(field);
            //执行重载
            table.reload('table', {where: field});
        });

        table.on('radio(table)', function(obj){

            $("#userOid").val(obj.data.oid);
            $("#userName").val(obj.data.name);
        });

    });

</script>
</body>
</html>
